<?php

/**
 * Форматирует денежную величину.
 *
 * @param   float   $value
 * @param   string  $currency
 * @param   boolean $sign
 * @return  string
 */
function smarty_modifier_money($value, $currency = '$', $sign = true) {
    if (!is_numeric($value)) {
        return $value;
    }
    foreach (array_slice(func_get_args(), 1) as $arg) {
        switch (gettype($arg)) {
            case 'string':
                $currency = $arg;
                break;
            case 'boolean':
                $sign = $arg;
                break;
        }
    }
    return ($value < 0 ? '-' : '')
         . ($sign ? $currency : '')
         . number_format(abs($value), '¥' != $currency ? 2 : 0, '.', ',');
}
